package com.polaris.live.adapter.recharge

import android.graphics.Paint
import android.view.View
import com.bumptech.glide.Glide
import com.lxj.xpopup.core.CenterPopupView
import com.polaris.live.R
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.common.constant.PayConst
import com.polaris.live.common.ext.convertArabicDigitsToNormal
import com.polaris.live.common.util.DateUtils
import com.polaris.live.databinding.AdapterRechargeBinding
import com.polaris.live.resp.back_resp.PayerRechargePriceListVo
import com.polaris.live.utils.image.ImageUtils

/**
 * 充值页面的adapter
 *
 * @author Created by 半仙 on 2023/9/4/004 12:38
 */
class RechargeAdapter :
    BaseBindingAdapter<AdapterRechargeBinding, PayerRechargePriceListVo>() {

    init {
        addChildClickViewIds(R.id.recharge_item_need_money)
    }

    override fun convert(
        holder: VBViewHolder<AdapterRechargeBinding>,
        item: PayerRechargePriceListVo,
    ) {
        holder.vb.apply {
            notPriceText.paintFlags = notPriceText.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
            rechargeItemNeedMoney.text = "\$${item.price}"

            if (item.coin == 0L) {
                notPriceText.visibility = View.GONE
            } else {
                notPriceText.visibility = View.VISIBLE
                notPriceText.text = "${item.coin}"
            }

            rechargeItemExGratia.visibility = View.VISIBLE
            rechargeItemExGratiaImg.visibility = View.VISIBLE
            rechargeItemExGratiaText.visibility = View.VISIBLE
            rechargeItemTimeLl.visibility = View.VISIBLE
            rechargeBack.setBackgroundResource(R.drawable.r8_back_ffffff)

            if (item.giveCoin == 0L) {
                okPriceText.visibility = View.GONE
                notPriceText.visibility = View.GONE
                rechargeItemExGratiaText.visibility = View.GONE
                rechargeItemExGratiaImg.visibility = View.GONE
                rechargeItemTimeLl.visibility = View.GONE
                rechargeItemExGratia.visibility = View.GONE
            } else {
                okPriceText.visibility = View.VISIBLE
                okPriceText.text = "+${item.giveCoin}"
            }



            rechargeItemText.text = "${(item.coin + item.giveCoin)}"

            Glide.with(context).load(ImageUtils.imgPath(item.icon))
                .into(ivCoin)

            if (item.rewardsExp != 0L) {
                firstRechargeTimeText.visibility = View.VISIBLE
                item.rewardsExp.let {
                    firstRechargeTimeText.text = DateUtils.minuteSChangeTime(it).convertArabicDigitsToNormal()
                }
            } else {
                rechargeItemTimeLl.visibility = View.GONE
            }

            when (item.payerRechargeRewardsType) {
                PayConst.RechargeListType.NOT -> {
                    rechargeItemTimeLl.visibility = View.GONE
                }

                PayConst.RechargeListType.FIRST_CHARGE -> {
                    if (holder.layoutPosition == 0) {
                        rechargeBack.setBackgroundResource(R.drawable.r8_gradient_fffed8_fff6bf)
                    }
                    rechargeItemExGratiaText.visibility = View.GONE
                }
            }

            if (item.extraReward != null) {
                reLlEx.visibility = CenterPopupView.VISIBLE
                jiaTv.visibility = CenterPopupView.VISIBLE
                rechargeItemExGratiaText2.visibility = CenterPopupView.VISIBLE
                rechargeExCount.visibility = CenterPopupView.VISIBLE
                yuanLl.setBackgroundResource(R.drawable.r8_back_f6f6f6_30)
                rechargeExCount.text = "X${item.extraReward.number}"
                Glide.with(context).load(ImageUtils.imgPath(item.extraReward.icon)).into(ivCoinEx)
                rechargeItemTextEx.text = "${item.extraReward.coin}"
            } else {
                reLlEx.visibility = CenterPopupView.GONE
                jiaTv.visibility = CenterPopupView.GONE
                rechargeItemExGratiaText2.visibility = CenterPopupView.GONE
                rechargeExCount.visibility = CenterPopupView.GONE
                yuanLl.setBackgroundResource(0)
            }
        }
    }
}